$(function() {
    getjycxinfo();
    $("#ljbdsmk").click(function() {
        if ($(".bxz").length > 0) {
            var cardNosArr = [];
            $(".bxz").each(function(i, t) {
                cardNosArr.push($(t).attr("cardno"));
            })
            console.log(cardNosArr)
            var data = {
                token: sessionStorage.token,
                userId: localStorage.userId,
                cardType: $(".all").attr("cardType"),
                paperNo: $(".all").attr("paperNo"),
                paperType: $(".all").attr("paperType"),
                cardNos: cardNosArr
            }
            $.ajax({
                url: requestUrl + "app/user/bind.do",
                type: "POST",
                data: data,
                dataType: "JSON",
                success: function(json) {
                    if (json.code == 0) {
                    	window.location.href="wdsmk.html";
                    }
                }
            })
        } else {
            alert("请选择绑定的市民卡！");
        }
    })
})

function getjycxinfo() {
    $.ajax({
        url: requestUrl + "app/user/isCardBinded.do",
        type: "POST",
        data: { token: sessionStorage.token, userId: localStorage.userId, isBinded: 0, paperNo: localStorage.codeNum, paperType: localStorage.codeType },
        dataType: "JSON",
        success: function(json) {
            if (json.code == 0) {
                if (json.data.length > 0) {
                    $(".all").attr("paperType", json.data[0].paperType);
                    $(".all").attr("paperNo", json.data[0].paperNo);
                    $(".all").attr("cardType", json.data[0].cardpCode);
                    $(json.data).each(function(i, t) {
                        var div = $("<div class='kcard' cardNo='" + t.citizenCardNo + "' cardpCode='" + t.cardpCode + "' paperNo='" + t.paperNo + "' paperType='" + t.paperType + "' zt='0'><div class='klex'>" + t.cardpName + "/" + t.cardTypeName + "</div><div class='kh'>" + t.citizenCardNo + "</div><img src='images/xzsmk0.png' class='xzimg'></div>").appendTo(".all");
                    })
                }

                $(".kcard").click(function() {
                    if ($(this).attr("zt") == 0) {
                        $(this).find(".xzimg").attr("src", "images/xzsmk1.png");
                        $(this).attr("zt", "1")
                        $(this).addClass("bxz")
                    } else if ($(this).attr("zt") == 1) {
                        $(this).find(".xzimg").attr("src", "images/xzsmk0.png");
                        $(this).attr("zt", "0")
                        $(this).removeClass("bxz")
                    }
                })
            }else{
                alert(json.message)
            }
        }
    })
}